import service from '@/axios/http'
import { TableIResponse } from '@/utils/Api'
import { FacilityTypeTreeData, FacilityTypeList, AddFacilityType } from './type'
export class EquipTypeApi {
  //查询设施类型树结构
  async GetFacilityTypeTree(): Promise<FacilityTypeTreeData[]> {
    const result = (await service.get(
      '/api/patrol/facilityType/facilityTypeTree'
    )) as unknown as any
    const { code, data } = result
    if (code == 200) {
      return data
    } else {
      return []
    }
  }
  //查询查询设施类型列表

  async GetFacilityTypeDetail(faciId: number | undefined): Promise<FacilityTypeList> {
    const result = (await service.get(`/api/patrol/facilityType/${faciId}`)) as unknown as any
    const { code, data } = result
    if (code == 200) {
      return data
    } else {
      return {}
    }
  }

  //新增设施类型列表
  async AddFacilityType(data: AddFacilityType): Promise<boolean> {
    const result = (await service.post('/api/patrol/facilityType', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }

  //修改设施类型列表
  async EditFacilityType(data: AddFacilityType): Promise<boolean> {
    const result = (await service.put('/api/patrol/facilityType', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //改设施类型列表
  async DeletFacilityType(id: number | undefined): Promise<boolean> {
    const result = (await service.delete(`/api/patrol/facilityType/${id}`)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //   查询设施类型配置表单列表
  //查询查询设施类型列表

  async GetFacTypeConfigList(params: any): Promise<TableIResponse<FacilityTypeList[]>> {
    const result = (await service.get('/api/patrol/facTypeConfig/list', {
      params
    })) as unknown as any
    return result
  }
  //新增设施类型配置表单
  async AddFacTypeConfig(data: FacilityTypeList): Promise<boolean> {
    const result = (await service.post('/api/patrol/facTypeConfig', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //修改设施类型列表
  async EditFacTypeConfig(data: FacilityTypeList): Promise<boolean> {
    const result = (await service.put('/api/patrol/facTypeConfig', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //删除设施类型列表
  async DeletFacTypeConfig(Id: number): Promise<boolean> {
    const result = (await service.delete(`/api/patrol/facTypeConfig/${Id}`)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //模板上传接口
  async FacTypeConfig(data: any): Promise<boolean> {
    const result = (await service.put('/api/patrol/facTypeConfig', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //根据ID查询详情(模板)
  async GetFacilityById(id: number | undefined): Promise<FacilityTypeList> {
    const result = (await service.get(`/api/patrol/facTypeConfig/${id}`)) as unknown as any
    const { code, data } = result
    if (code == 200) {
      return data
    } else {
      return {}
    }
  }
  //根据faciId查询详情(模板)
  async GetFacilityByFaciId(faciId: number | undefined): Promise<FacilityTypeList> {
    const result = (await service.get(
      `/api/patrol/facTypeConfig/getFacInfo/${faciId}`
    )) as unknown as any
    const { code, data } = result
    if (code == 200) {
      return data
    } else {
      return {}
    }
  }
}
export default new EquipTypeApi()
